package com.battery.web.controller.system.battery;

import java.util.List;

import com.battery.system.domain.BO.StoreBO;
import com.battery.system.domain.Merchant;
import com.battery.system.domain.VO.MerchantExcelVO;
import com.battery.system.domain.VO.StoreDetailVo;
import com.battery.system.domain.VO.StoreVO;
import com.battery.system.service.ISysDictDataService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.battery.common.annotation.Log;
import com.battery.common.enums.BusinessType;
import com.battery.system.domain.Store;
import com.battery.system.service.battery.IStoreService;
import com.battery.common.core.controller.BaseController;
import com.battery.common.core.domain.AjaxResult;
import com.battery.common.utils.poi.ExcelUtil;
import com.battery.common.core.page.TableDataInfo;

/**
 * 门店信息Controller
 *
 * @author battery
 * @date 2021-01-23
 */
@Controller
@RequestMapping("/system/store")
public class StoreController extends BaseController {
    private String prefix = "system/store";

    @Autowired
    private IStoreService storeService;


    @Autowired
    private ISysDictDataService dictDataService;


    /**
     * 跳转到商户门店列表
     *
     * @return
     */
    @RequiresPermissions("system:store_merchant:view")
    @GetMapping("/store_merchant")
    public String merchant_store() {
        return prefix + "/store_merchant";
    }


    @RequiresPermissions("system:store:view")
    @GetMapping()
    public String store() {
        return prefix + "/store";
    }

    /**
     * 查询门店信息列表
     */
    @RequiresPermissions("system:store:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(StoreBO storeBO) {
        startPage();
//        List<Store> list = storeService.selectStoreList(store);
        List<StoreVO> list = storeService.selectStoreVOList(storeBO);
        return getDataTable(list);
    }

    /**
     * 导出门店信息列表
     */
    @RequiresPermissions("system:store:export")
    @Log(title = "门店信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(StoreBO storeBO) {
        List<MerchantExcelVO> list = storeService.selectStoreExcelVOList(storeBO);
        ExcelUtil<MerchantExcelVO> util = new ExcelUtil<MerchantExcelVO>(MerchantExcelVO.class);
        return util.exportExcel(list, "store");
    }

    /**
     * 新增门店信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存门店信息
     */
    @RequiresPermissions("system:store:add")
    @Log(title = "门店信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Store store) {
        return toAjax(storeService.insertStore(store));
    }

    /**
     * 修改门店信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        Store store = storeService.selectStoreById(id);
        mmap.put("store", store);
        return prefix + "/edit";
    }

    /**
     * 修改保存门店信息
     */
    @RequiresPermissions("system:store:edit")
    @Log(title = "门店信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Store store) {
        return toAjax(storeService.updateStore(store));
    }

    /**
     * 删除门店信息
     */
    @RequiresPermissions("system:store:remove")
    @Log(title = "门店信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(storeService.deleteStoreByIds(ids));
    }


    /**
     * 查看详情
     */
    @GetMapping("/seeDetail/{id}")
    public String seeDetail(@PathVariable("id") String id, ModelMap mmap) {
        StoreDetailVo storeDetailVo = storeService.selectStoreDetailVo(id);
        mmap.put("storeDetailVo", storeDetailVo);
        return prefix + "/seeDetail";
    }


    /**
     * 设备营业额
     *
     * @param id
     * @param mmap
     * @return
     */
    @GetMapping("/devIncomes/{id}")
    public String devIncomes(@PathVariable("id") String id, ModelMap mmap) {
        mmap.put("storeId", id);
        return prefix + "/devIncomes";
    }

}
